home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Overview / TESample / AUX / TESample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  12.9 KB  |  336 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware TextEdit Sample Application
  6. #
  7. #    TESample
  8. #
  9. #    TESample.h    -    Rez and C Include Source
  10. #
  11. #    Copyright ) 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #                1.00                08/88
  16. #                1.01                11/88
  17. #                1.02                04/89
  18. #                1.03                06/89
  19. #
  20. #    Components:
  21. #                TESample.p            June 1, 1989
  22. #                TESample.c            June 1, 1989
  23. #                TESampleGlue.a        June 1, 1989    -MPW only-
  24. #                TESample.r            June 1, 1989
  25. #                TESample.h            June 1, 1989
  26. #                PTESample.make        June 1, 1989    -MPW only-
  27. #                CTESample.make        June 1, 1989    -MPW only-
  28. #                TESampleGlue.s        June 1, 1989    -A/UX only-
  29. #                TESampleAUX.r        June 1, 1989    -A/UX only-
  30. #                Makefile            June 1, 1989    -A/UX only-
  31. #
  32. #    TESample is an example application that demonstrates how 
  33. #    to initialize the commonly used toolbox managers, operate 
  34. #    successfully under MultiFinder, handle desk accessories and 
  35. #    create, grow, and zoom windows. The fundamental TextEdit 
  36. #    toolbox calls and TextEdit autoscroll are demonstrated. It 
  37. #    also shows how to create and maintain scrollbar controls.
  38. #
  39. #    It does not by any means demonstrate all the techniques you 
  40. #    need for a large application. In particular, Sample does not 
  41. #    cover exception handling, multiple windows/documents, 
  42. #    sophisticated memory management, printing, or undo. All of 
  43. #    these are vital parts of a normal full-sized application.
  44. #
  45. #    This application is an example of the form of a Macintosh 
  46. #    application; it is NOT a template. It is NOT intended to be 
  47. #    used as a foundation for the next world-class, best-selling, 
  48. #    600K application. A stick figure drawing of the human body may 
  49. #    be a good example of the form for a painting, but that does not 
  50. #    mean it should be used as the basis for the next Mona Lisa.
  51. #
  52. #    We recommend that you review this program or Sample before 
  53. #    beginning a new application. Sample is a simple app. which doesnUt 
  54. #    use TextEdit or the Control Manager.
  55. #
  56. ------------------------------------------------------------------------------*/
  57.  
  58. /* Function prototypes for all functions in this program. */
  59. /* In MPW 3.0 we can use actual prototypes for parameter type checking. */
  60. /* A/UX C does not grok prototypes, so eliminate them under A/UX */
  61. #ifndef rez
  62. #ifndef AUX
  63.     void AlertUser( short error );
  64.     void EventLoop( void );
  65.     void DoEvent( EventRecord *event );
  66.     void AdjustCursor( Point mouse, RgnHandle region );
  67.     void GetGlobalMouse( Point *mouse );
  68.     void DoGrowWindow( WindowPtr window, EventRecord *event );
  69.     void DoZoomWindow( WindowPtr window, short part );
  70.     void ResizeWindow( WindowPtr window );
  71.     void GetLocalUpdateRgn( WindowPtr window, RgnHandle localRgn );
  72.     void DoUpdate( WindowPtr window );
  73.     void DoDeactivate( WindowPtr window );
  74.     void DoActivate( WindowPtr window, Boolean becomingActive );
  75.     void DoContentClick( WindowPtr window, EventRecord *event );
  76.     void DoKeyDown( EventRecord *event );
  77.     unsigned long GetSleep( void );
  78.     void CommonAction( ControlHandle control, short *amount );
  79.     pascal void VActionProc( ControlHandle control, short part );
  80.     pascal void HActionProc( ControlHandle control, short part );
  81.     void DoIdle( void );
  82.     void DrawWindow( WindowPtr window );
  83.     void AdjustMenus( void );
  84.     void DoMenuCommand( long menuResult );
  85.     void DoNew( void );
  86.     Boolean DoCloseWindow( WindowPtr window );
  87.     void Terminate( void );
  88.     void Initialize( void );
  89.     void BigBadError( short error );
  90.     void GetTERect( WindowPtr window, Rect *teRect );
  91.     void AdjustViewRect( TEHandle docTE );
  92.     void AdjustTE( WindowPtr window );
  93.     void AdjustHV( Boolean isVert, ControlHandle control, TEHandle docTE,
  94.                     Boolean canRedraw );
  95.     void AdjustScrollValues( WindowPtr window, Boolean canRedraw );
  96.     void AdjustScrollSizes( WindowPtr window );
  97.     void AdjustScrollbars( WindowPtr window, Boolean needsResize );
  98.     pascal void PascalClickLoop();
  99.     pascal TEClickLoopUPP GetOldClickLoop();
  100.     Boolean IsAppWindow( WindowPtr window );
  101.     Boolean IsDAWindow( WindowPtr window );
  102.     Boolean TrapAvailable( short tNumber, TrapType tType );
  103. #else
  104.     void AlertUser( );
  105.     void EventLoop( );
  106.     void DoEvent( );
  107.     void AdjustCursor( );
  108.     void GetGlobalMouse( );
  109.     void DoGrowWindow( );
  110.     void DoZoomWindow( );
  111.     void ResizeWindow( );
  112.     void GetLocalUpdateRgn( );
  113.     void DoUpdate( );
  114.     void DoDeactivate( );
  115.     void DoActivate( );
  116.     void DoContentClick( );
  117.     void DoKeyDown( );
  118.     unsigned long GetSleep( );
  119.     void CommonAction( );
  120.     void VActionProc( );
  121.     void HActionProc( );
  122.     void DoIdle( );
  123.     void DrawWindow( );
  124.     void AdjustMenus( );
  125.     void DoMenuCommand( );
  126.     void DoNew( );
  127.     Boolean DoCloseWindow( );
  128.     void Terminate( );
  129.     void Initialize( );
  130.     void BigBadError( ); 
  131.     void GetTERect( );
  132.     void AdjustViewRect( );
  133.     void AdjustTE( );
  134.     void AdjustHV( );
  135.     void AdjustScrollValues( );
  136.     void AdjustScrollSizes( );
  137.     void AdjustScrollbars( );
  138.     void PascalClickLoop();
  139.     TEClickLoopUPP GetOldClickLoop();
  140.     Boolean IsAppWindow( );
  141.     Boolean IsDAWindow( );
  142.     Boolean TrapAvailable( );
  143. #endif
  144. #endif
  145.  
  146. /*    These #defines correspond to values in the Pascal source code.
  147.     TESample.c and TESample.r include this file. */
  148.  
  149. /*    Determining an application's minimum size to request from MultiFinder depends
  150.     on many things, each of which can be unique to an application's function,
  151.     the anticipated environment, the developer's attitude of what constitutes
  152.     reasonable functionality and performance, etc. Here is a list of some things to
  153.     consider when determining the minimum size (and preferred size) for your
  154.     application. The list is pretty much in order of importance, but by no means
  155.     complete.
  156.     
  157.     1.    What is the minimum size needed to give almost 100 percent assurance
  158.         that the application won't crash because it ran out of memory? This
  159.         includes not only things that you do have direct control over such as
  160.         checking for NIL handles and pointers, but also things that some
  161.         feel are not so much under their control such as QuickDraw and the
  162.         Segment Loader.
  163.         
  164.     2.    What kind of performance can a user expect from the application when
  165.         it is running in the minimum memory configuration? Performance includes
  166.         not only speed in handling data, but also things like how many documents
  167.         can be opened, etc.
  168.         
  169.     3.    What are the typical sizes of scraps is [a boy dog] that a user might
  170.         wish to work with when lauching or switching to your application? If
  171.         the amount of memory is too small, the scrap may get lost [will have
  172.         to be shot]. This can be quite frustrating to the user.
  173.         
  174.     4.    The previous items have concentrated on topics that tend to cause an
  175.         increase in the minimum size to request from MultiFinder. On the flip
  176.         side, however, should be the consideration of what environments the
  177.         application may be running in. There may be a high probability that
  178.         many users with relatively small memory configurations will want to
  179.         avail themselves of your application. Or, many users might want to use it
  180.         while several other, possibly related/complementary applications are
  181.         running. If that is the case, it would be helpful to have a fairly
  182.         small minimum size.
  183.     
  184.     What we did for TESample:
  185.     
  186.         We determined the smallest heap size that TESample could have and still
  187.         run (22K). For the preferred size we added enough space to permit:
  188.             a. a maximum size TextEdit text handle (32000 characters)
  189.             b. a maximum usable TextEdit scrap (32000 characters)
  190.             b. a maximum scrap as a result of Copy (32000 characters)
  191.             d. a little performance cushion (see 2, above) (10K)
  192.         Result: 122K for preferred size
  193.         
  194.         For the minimum size we took the 22K and then scaled down our requirements
  195.         for a,b, and c above. We thought that providing 16K more would be lean
  196.         and mean (see 4, above).
  197.         Result: 38K for minimum size
  198. */
  199.  
  200. #define kPrefSize                122
  201. #define kMinSize                38
  202.     
  203. /* The following constants are used to identify menus and their items. The menu IDs
  204.    have an "m" prefix and the item numbers within each menu have an "i" prefix. */
  205. #define    mApple                    128        /* Apple menu */
  206. #define    iAbout                    1
  207.  
  208. #define    mFile                    129        /* File menu */
  209. #define    iNew                    1
  210. #define    iClose                    4
  211. #define    iQuit                    12
  212.  
  213. #define    mEdit                    130        /* Edit menu */
  214. #define    iUndo                    1
  215. #define    iCut                    3
  216. #define    iCopy                    4
  217. #define    iPaste                    5
  218. #define    iClear                    6
  219.  
  220. /*    1.01 - kTopLeft - This is for positioning the Disk Initialization dialogs. */
  221.  
  222. #define kDITop                    0x0050
  223. #define kDILeft                    0x0070
  224.  
  225. /* 1.01 - changed constants to begin with 'k' for consistency, except for resource IDs */
  226. /*    kTextMargin is the number of pixels we leave blank at the edge of the window. */
  227. #define kTextMargin                2
  228.  
  229. /* kMaxOpenDocuments is used to determine whether a new document can be opened
  230.    or created. We keep track of the number of open documents, and disable the
  231.    menu items that create a new document when the maximum is reached. If the
  232.    number of documents falls below the maximum, the items are enabled again. */
  233. #define    kMaxOpenDocuments        1
  234.     
  235. /*    kMaxDocWidth is an arbitrary number used to specify the width of the TERec's
  236.     destination rectangle so that word wrap and horizontal scrolling can be
  237.     demonstrated. */
  238. #define    kMaxDocWidth            576
  239.     
  240. /* kMinDocDim is used to limit the minimum dimension of a window when GrowWindow
  241.     is called. */
  242. #define    kMinDocDim                64
  243.  
  244. /*    kControlInvisible is used to 'turn off' controls (i.e., cause the control not
  245.     to be redrawn as a result of some Control Manager call such as SetCtlValue)
  246.     by being put into the contrlVis field of the record. kControlVisible is used
  247.     the same way to 'turn on' the control. */
  248. #define kControlInvisible        0
  249. #define kControlVisible            0xFF
  250.  
  251. /*    kScrollbarAdjust and kScrollbarWidth are used in calculating
  252.     values for control positioning and sizing. */
  253. #define kScrollbarWidth            16
  254. #define kScrollbarAdjust        (kScrollbarWidth - 1)
  255.  
  256. /*    kScrollTweek compensates for off-by-one requirements of the scrollbars
  257.  to have borders coincide with the growbox. */
  258. #define kScrollTweek            2
  259.     
  260. /*    kCrChar is used to match with a carriage return when calculating the
  261.     number of lines in the TextEdit record. kDelChar is used to check for
  262.     delete in keyDowns. */
  263. #define kCrChar                    13
  264. #define kDelChar                8
  265.     
  266. /*    kButtonScroll is how many pixels to scroll horizontally when the button part
  267.     of the horizontal scrollbar is pressed. */
  268. #define kButtonScroll            4
  269.     
  270. /*    kMaxTELength is an arbitrary number used to limit the length of text in the TERec
  271.     so that various errors won't occur from too many characters in the text. */
  272. #define    kMaxTELength            32000
  273.  
  274. /* kSysEnvironsVersion is passed to SysEnvirons to tell it which version of the
  275.    SysEnvRec we understand. */
  276. #define    kSysEnvironsVersion        1
  277.  
  278. /* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
  279.    by MultiFinder. Once we determine that an event is an OSEvent, we look at the
  280.    high byte of the message sent to determine which kind it is. To differentiate
  281.    suspend and resume events we check the resumeMask bit. */
  282. #define    kOSEvent                app4Evt    /* event used by MultiFinder */
  283. #define    kSuspendResumeMessage    1        /* high byte of suspend/resume event message */
  284. #define    kResumeMask                1        /* bit of message field for resume vs. suspend */
  285. #define    kMouseMovedMessage        0xFA    /* high byte of mouse-moved event message */
  286. #define    kNoEvents                0        /* no events mask */
  287.  
  288. /* 1.01 - kMinHeap - This is the minimum result from the following
  289.      equation:
  290.             
  291.             ORD(GetApplLimit) - ORD(ApplicZone)
  292.             
  293.      for the application to run. It will insure that enough memory will
  294.      be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  295.      application, and still give the application some 'breathing room'.
  296.      To derive this number, we ran under a MultiFinder partition that was
  297.      our requested minimum size, as given in the 'SIZE' resource. */
  298.      
  299. #define    kMinHeap                 (29 * 1024)
  300.     
  301. /* 1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
  302.      at initialization time, for the application to run. This number acts
  303.      as a double-check to insure that there really is enough memory for the
  304.      application to run, including what has been taken up already by
  305.      pre-loaded resources, the scrap, code, and other sundry memory blocks. */
  306.      
  307. #define    kMinSpace                (20 * 1024)
  308.  
  309. /*    kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
  310. #define kExtremeNeg                -32768
  311. #define kExtremePos                (32767 - 1)    /* required to address an old region bug */
  312.     
  313. /* kTESlop provides some extra security when pre-flighting edit commands. */
  314. #define    kTESlop                    1024
  315.  
  316. /* The following are indicies into STR# resources. */
  317. #define    eWrongMachine            1
  318. #define    eSmallSize                2
  319. #define    eNoMemory                3
  320. #define    eNoSpaceCut                4
  321. #define    eNoCut                    5
  322. #define    eNoCopy                    6
  323. #define    eExceedPaste            7
  324. #define    eNoSpacePaste            8
  325. #define    eNoWindow                9
  326. #define    eExceedChar                10
  327. #define    eNoPaste                11
  328.  
  329. #define    rMenuBar    128                /* application's menu bar */
  330. #define    rAboutAlert    128                /* about alert */
  331. #define    rUserAlert    129                /* user error alert */
  332. #define    rDocWindow    128                /* application's window */
  333. #define    rVScroll    128                /* vertical scrollbar control */
  334. #define    rHScroll    129                /* horizontal scrollbar control */
  335. #define    kErrStrings    128                /* error string list */
  336.